package com.autoai.animation.demo;

import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * @author Wangjw
 * @date 2020-12-17
 * @brief
 */
public class SecondFragment extends Fragment {
    TextView searchView;
    TextView musicView;
    Animation vr_layout_in;
    Animation vr_layout_out;
    Animation music_layout_in;
    Animation music_layout_out;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.lay_second_fragment, container, false);
        searchView = view.findViewById(R.id.tv_vr_layout);
        musicView = view.findViewById(R.id.tv_player_layout);
        vr_layout_in = AnimationUtils.loadAnimation(getContext(), R.anim.vr_layout_in);
        vr_layout_out = AnimationUtils.loadAnimation(getContext(), R.anim.vr_layout_out);
        music_layout_in = AnimationUtils.loadAnimation(getContext(), R.anim.music_layout_in);
        music_layout_out = AnimationUtils.loadAnimation(getContext(), R.anim.music_layout_out);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        layoutIn();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(hidden){

        } else {
            layoutIn();
        }
    }

    public void layoutIn(){
        vrLayoutIn();
        musicLayoutIn();
    }

    public void layoutOut(){
        vrLayoutOut();
        musicLayoutOut();
    }

    private void vrLayoutIn() {
        searchView.startAnimation(vr_layout_in);
        vr_layout_in.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                searchView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    private void musicLayoutIn(){
        musicView.startAnimation(music_layout_in);
        music_layout_in.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                musicView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    private void vrLayoutOut() {
        searchView.startAnimation(vr_layout_out);
        vr_layout_out.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                searchView.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    private void musicLayoutOut(){
        musicView.startAnimation(music_layout_out);
        music_layout_out.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                musicView.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }


}
